package com.project.common.domain;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.modelmapper.convention.NameTokenizers;

/**
 * Convert
 * 转换
 */
public class Convert{
    /**
     * 严格模式
     *
     * @param source
     * @param destinationType
     */
    public static void map(Object source, Object destinationType) {
        ModelMapper modelMapper = new ModelMapper();
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        modelMapper.map(source, destinationType);
    }

    /**
     * 严格模式跳过null
     *
     * @param source
     * @param destinationType
     */
    public static void mapSkipNull(Object source, Object destinationType) {
        ModelMapper modelMapper = new ModelMapper();
        modelMapper.getConfiguration().setSkipNullEnabled(true);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        modelMapper.map(source, destinationType);
    }

    /**
     * 驼峰->驼峰
     *
     * @param source
     * @param destinationType
     */
    public static void mapCcToCc(Object source, Object destinationType) {
        ModelMapper modelMapper = getConvert();
        modelMapper.getConfiguration().setSourceNameTokenizer(NameTokenizers.CAMEL_CASE);
        modelMapper.getConfiguration().setDestinationNameTokenizer(NameTokenizers.CAMEL_CASE);
        modelMapper.map(source, destinationType);
    }


    /**
     * 转换器
     *
     * @return
     */
    public static ModelMapper getConvert() {
        ModelMapper modelMapper = new ModelMapper();
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        return modelMapper;
    }
}
